
import api from '@/api/my-axios';
import type { LoginData,RegisterData,DataItem } from "@/type/type";

const baseURL='/users'
export const login = async (data: FormData) => {
    try {
        const response = await api.post(baseURL+'/login', data);
        
        localStorage.setItem('token', response.data.token); // 假设返回的 token 字段是 data.token
        return response.data;
    } catch (error) {
        throw error;
    }
};

export const register = async (data: FormData) => {
    try {
        const response = await api.post(baseURL+'/register', data);
        return response.data;
    } catch (error) {
        throw error;
    }
};

export const getUserInfo = async (data) => {
    try {
        const response = await api.get(baseURL+'/search',{params:{"userAccount":data}});
        return response.data;
    } catch (error) {
        throw error;
    }
};
export const getAllUsers = async () => {
    try {
        const response = await api.get<DataItem[]>(baseURL+'/all');
        return response.data;
    } catch (error) {
        throw error;
    }
};
export const update = async (formState:DataItem) => {
    try {
        const response = await api.put(baseURL+'/update', formState);
        return response.data;
    } catch (error) {
        throw error;
    }
};


// 获取验证码接口
// export const getCaptcha = async () => {

//     try {
//         const response = await api.get('/captchaImage');
//         return response.data;
//     } catch (error) {
//         throw error;
//     }
// };

// export const getUserList = async () => {
//     try {
//         const response = await api.get('/system/user/list');
//         return response.data;
//     } catch (error) {
//         throw error;
//     }
// };
